package com.healthcloud.controller.modules.losewisdom;

import com.healthcloud.dto.req.losewisdom.LoseWisdomFollowUpListReq;
import com.healthcloud.entity.MsgVo;
import com.healthcloud.entity.losewisdom.LoseWisdomFollowUpEntity;
import com.healthcloud.service.losewisdom.LoseWisdomFollowUpService;
import com.healthcloud.utils.ApiRes;
import com.healthcloud.utils.PageParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 失智老人随访
 */
@Controller
@RequestMapping("/lose/wisdom/follow/up")
public class LWFollowUpController {

    @Autowired
    private LoseWisdomFollowUpService followUpService;

    @GetMapping("/index")
    public String index(){
        return "losewisdom/followUp/followUp";
    }

    @ApiOperation("跳转至随访更多页面")
    @GetMapping("/more")
    public String more() {
        return "losewisdom/followUp/more";
    }

    @ApiOperation("跳转至随访修改页面")
    @GetMapping("/toUpdate")
    public String toUpdate(@RequestParam("id") Integer id, ModelMap map) {
        map.put("entity", followUpService.queryObject(id));
        return "losewisdom/followUp/edit";
    }

    /**
     * 获取随访列表
     * @param req
     * @param pageParam
     * @return
     */
    @ApiOperation("获取随访列表")
    @PostMapping("/list")
    @ResponseBody
    public MsgVo list(LoseWisdomFollowUpListReq req, @ModelAttribute("pageParam")PageParam pageParam) {
        List<LoseWisdomFollowUpEntity> list = followUpService.queryList(req, pageParam);
        int count = followUpService.queryTotal(req);
        return new MsgVo(list,count,count,pageParam.getsEcho());
    }

    /**
     * 获取随访详情
     * @param id
     * @return
     */
    @ApiOperation("获取随访详情")
    @PostMapping("/detail")
    @ResponseBody
    public ApiRes getById(Integer id) {
        LoseWisdomFollowUpEntity entity = followUpService.queryObject(id);
        return ApiRes.success(entity);
    }

    /**
     * 新增随访记录
     * @param entity
     * @return
     */
    @ApiOperation("新增随访记录")
    @PostMapping("/save")
    @ResponseBody
    public ApiRes save(LoseWisdomFollowUpEntity entity) {
        followUpService.save(entity);
        return ApiRes.success();
    }

    /**
     * 修改随访记录
     * @param entity
     * @return
     */
    @ApiOperation("修改随访记录")
    @PostMapping("/update")
    @ResponseBody
    public ApiRes update(LoseWisdomFollowUpEntity entity) {
        followUpService.update(entity);
        return ApiRes.success();
    }

    /**
     * 删除随访记录
     * @param id
     * @return
     */
    @ApiOperation("删除随访记录")
    @PostMapping("/delete")
    @ResponseBody
    public ApiRes delete(Integer id) {
        followUpService.delete(id);
        return ApiRes.success();
    }


}
